package cn.jtfadmin.core.modules.sys.domain.entity;


import cn.jtfadmin.base.data.jpa.domain.entity.BaseEntity;
import cn.jtfadmin.base.lang.common.domain.entity.NamedEntity;
import cn.jtfadmin.base.lang.enums.BooleanEnum;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * 系统角色
 *
 * @author jtf
 * @version 1.0
 * @since 1.0
 */
@Getter
@Setter
@Table(name = "sys_role")
@Entity
public class SysRoleEntity extends BaseEntity implements NamedEntity {

    /**
     * 角色名称
     */
    @Column(name = "name", nullable = false, length = 200)
    @NotBlank
    @Size(max = 200)
    protected String name;

    /**
     * 角色编码
     */
    @Column(name = "code", nullable = false, length = 200, unique = true)
    @Size(max = 200)
    @NotBlank
    protected String code;


    /**
     * 描述
     */
    @Column(name = "description")
    @Size(max = 200)
    protected String description;

    /**
     * 是否是超级管理员
     */
    @Column(name = "admin_flag")
    protected BooleanEnum adminFlag;


    /**
     * 数据范围
     */
    @Column(name = "data_range")
    @Lob
    protected String dataRange;


    /**
     * 具有角色的用户实体
     */
    @ManyToMany()
    @JoinTable(name = "sys_user_role", inverseJoinColumns = @JoinColumn(name = "user_id"), joinColumns = @JoinColumn(name = "role_id"))
    private List<SysUserEntity> userList;


    /**
     * 角色具有的权限实体
     */
    @ManyToMany()
    @JoinTable(name = "sys_role_permission",
            joinColumns = @JoinColumn(name = "role_id"),
            inverseJoinColumns = @JoinColumn(name = "permission_id")
    )
    private List<SysPermissionEntity> permissionList;


    /**
     * 角色归属机构
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "sys_depart_id")
    private SysDepartEntity sysDepart;

}
